package com.zcx.controller;


import com.zcx.pojo.dto.StudentCrouseDto;
import com.zcx.pojo.dto.Vertify;
import com.zcx.pojo.vo.ClazzVo;
import com.zcx.pojo.vo.CollegeVo;
import com.zcx.pojo.vo.JSONResult;
import com.zcx.pojo.vo.StudentVo;
import com.zcx.service.SpringService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TestController {

    @Autowired
    private SpringService springService;


    JSONResult jsonResult = new JSONResult();

    @PostMapping("/login")
    public JSONResult login(@RequestBody Vertify vertify){

        System.out.println(vertify);
        if(springService.queryuser(vertify)){
            jsonResult.ok("成功登录");
        }else{
            jsonResult.error("请重新输入");
        }
        System.out.println(jsonResult);
        return jsonResult;
    }

    //
    @GetMapping("/clazz-list")
    public JSONResult queryClass(){

        List<CollegeVo> queryclass = springService.querycalss();
        System.out.println(springService.querycalss());
        jsonResult.ok()
                .put("clazzList",queryclass);
        System.out.println(jsonResult);
        return jsonResult;
    }

    //查询每个班学生的信息
    @GetMapping("/student-list/{clazzName}")
    public JSONResult queryStudent(@PathVariable("clazzName") String clazzName){

        List<ClazzVo> querystudent = springService.querystudent(clazzName);
        System.out.println(springService.querystudent(clazzName));
        jsonResult.ok()
                .put("studentList",querystudent);
        System.out.println(jsonResult);
        return jsonResult;
    }

    //查询学生个人信息
    @GetMapping("/get-student-info/{num}")
    public JSONResult queryPerson(@PathVariable("num") String num){
        List<StudentVo> queryperson = springService.queryperson(num);
        System.out.println(queryperson);
        jsonResult.ok()
                .put("studentInfo",queryperson);
        System.out.println(jsonResult);
        return jsonResult;
    }

    @GetMapping("/delete-stu/{num}")
    public JSONResult deletePerson(@PathVariable("num") String num){
        System.out.println(num);
        if(springService.deleteperson(num)){
            jsonResult.ok("删除成功");
        }else{
            jsonResult.error("操作失败");
        }
        return jsonResult;
    }

    @PostMapping("/update-student-course-info")
    public JSONResult updatePerson(@RequestBody StudentCrouseDto studentCrouseDto){
        System.out.println(studentCrouseDto);
        int updateperson = springService.updateperson(studentCrouseDto);
        System.out.println(updateperson);
        jsonResult.ok("更新成功");
        System.out.println(jsonResult);
        return jsonResult;
    }

}
